# Reference: <https://postmarketos.org/devicepkg>
# Maintainer: chalkin Deng <chalkin@yeah.net>
pkgname=device-lenovo-q706f
pkgdesc="Lenovo Xiaoxin Pad Pro 12.6 (Lenovo Tab P12 Pro)"
pkgver=4
pkgrel=0
url="https://postmarketos.org"
license="MIT"
arch="aarch64"
options="!check !archcheck"
depends="
	bootmac
	hexagonrpcd
	linux-lenovo-q706f
	make-dynpart-mappings
	mesa-vulkan-freedreno
	mkbootimg
	postmarketos-base
	qbootctl
	swclock-offset
"
makedepends="devicepkg-dev"
replaces="hexagonrpcd-openrc"
source="
	81-libssc-lenovo-q706f.rules
	alsa-ucm-conf/q706f.conf
	alsa-ucm-conf/HiFi.conf
	deviceinfo
	hexagonrpcd.confd
	modules-initfs
"

subpackages="
	$pkgname-nonfree-firmware:nonfree_firmware
	$pkgname-nonfree-firmware-openrc:nonfree_firmware_openrc
	$pkgname-openrc
"

build() {
	devicepkg_build $startdir $pkgname
}

package() {
	devicepkg_package $startdir $pkgname

	# device-specific alsa ucm conf
	install -Dm644 "$srcdir/q706f.conf" \
		"$pkgdir/usr/share/alsa/ucm2/Lenovo/q706f/q706f.conf"

	install -Dm644 "$srcdir/HiFi.conf" \
		"$pkgdir/usr/share/alsa/ucm2/Lenovo/q706f/HiFi.conf"

	mkdir -p "$pkgdir/usr/share/alsa/ucm2/conf.d/sm8250"
	ln -s ../../Lenovo/q706f/q706f.conf \
		"$pkgdir/usr/share/alsa/ucm2/conf.d/sm8250/Xiaoxin Pad Pro.conf"

	install -Dm644 "$srcdir"/81-libssc-lenovo-q706f.rules \
		"$pkgdir"/usr/lib/udev/rules.d/81-libssc-lenovo-q706f.rules
}

nonfree_firmware() {
	pkgdesc="Firmware for GPU, WiFi, etc."
	depends="
		firmware-lenovo-q706f-adreno
		firmware-lenovo-q706f-adsp
		firmware-lenovo-q706f-cdsp
		firmware-lenovo-q706f-cirrus
		firmware-lenovo-q706f-hexagonfs
		firmware-lenovo-q706f-slpi
		firmware-lenovo-q706f-venus
		linux-firmware-ath11k
		linux-firmware-qca
		pd-mapper
		tqftpserv
		"
	mkdir "$subpkgdir"
}

nonfree_firmware_openrc() {
	install_if="$pkgname-nonfree-firmware=$pkgver-r$pkgrel openrc"
	install="$subpkgname.post-install $subpkgname.post-upgrade"

	mkdir "$subpkgdir"
}

openrc() {
	install_if="$pkgname=$pkgver-r$pkgrel openrc"
	install="$subpkgname.post-install $subpkgname.post-upgrade"

	install -Dm644 "$srcdir"/hexagonrpcd.confd \
		"$subpkgdir"/etc/conf.d/hexagonrpcd-sdsp
}

sha512sums="
1e0f02d47ea87d467c6e9d824d3b021c97ff29af8fcdf67ac1b75baa2b835f1dcdfc0c9f308a0bdeb3cdf07a8c1e26d66bff8d1337c9cfab1df94c26e9ccfb81  81-libssc-lenovo-q706f.rules
7c97ffb7ae3e1fa2e62bdb3c504275db2c830cc1e5b57dd409ae14d020a1ff5f5cb922223c5dd776569cff52415afd26cba83b6acd76aef22a79ffdaf18dcfbd  q706f.conf
1e93599051d6dfe96a07ca230df9c02ad78126c74ec2295098904d646a9df794378744174b877b4b7ca491fa06c336b0d733c421a81eab23c2bece577610b252  HiFi.conf
6b3d7e3af7f6bc3f32c472112f831827fbdc05e7b16582e204730250f7d1b293f558d7e53ed986d4b1fe2879ee841c7be63bc015421d206fe443325c3c788ccc  deviceinfo
75b2087fa574fa39ef42fce17effb1330bd1318d945de3a91094a5a22812fcfe458821f1dd76e5f48a90c525e17169247520b848596107cc7f843cbcfcb5e1c7  hexagonrpcd.confd
c0634ddd66ecfe4b39e8bff0b17ea141303d8827d7d498c2a9f19729566f0d5a3900c78ac8c71e8ef5d68e67c625d551e67c790ea01b103fcf38848e8aebfdf1  modules-initfs
"
